<template>
	<view class="cell-page">
			<uni-card>
				<u-form-item>
					<u-input v-model="useremail" placeholder="" disabled />
				</u-form-item>
				<u-form-item>
					<u-input v-model="emailCode" placeholder="请填写验证码"></u-input>
					<u-button slot="right" @click="getCode" type="success" size="mini" >
						{{!tips?'获取验证码':tips+'s'}}
					</u-button>
				</u-form-item>
				<u-form-item>
					<u-input v-model="userEmail2" placeholder="请输入新邮箱" />
				</u-form-item>
				<button style="margin-bottom: 20px;" type="primary" @click="submit()">提交</button>
			</uni-card>
		</view>
</template>

<script>
import request from '../../request.js'
	export default {
		data() {
			return {
				tips:0,
				useremail:'',
				emailCode:'',
				userEmail2:'',
			}
		},
		onLoad(w) {
				this.userId=w.userId
			this.load()
		},
		methods: {
			load(){
				console.log(this.userId)
				request({
					url:"xkuser/user/load/"+this.userId,
					method:'get',
					success:(res)=>{
						this.arr=res.data.data.arr
								this.useremail=this.arr.email
								console.log(this.arr)
					}
				})
			},
			getCode(){
				if(this.tips>0){
					uni.showToast({
						title:'不能重复获取',
						 icon:"none"
					});
					return;
				}else{
					this.tips = 60
					let timer = setInterval(()=>{
						this.tips--;
						if(this.tips<1){
							clearInterval(timer);
							this.tips = 0;
						}
					},1000)	
					request({
						url:"xkuser/user/hqyzm/"+this.useremail,
						method:'get',
						success:(res)=>{
							this.arr=res.data.data.email
							console.log(this.arr)		
						}
					})
				}
			},
			submit(){
				if(this.emailCode == '' || this.emailCode!=this.arr){
					uni.showToast({
						title:'验证码错误',
						icon:'none',
					});
					return;
				}
				if (this.userEmail2 == '') {
									uni.showToast({
										title: '新邮箱不能为空！',
										icon: 'none',
										duration: 2000
									});
									return;
								}
				request({
					url:"xkuser/user/updateemail/" +this.userId+ '/' +this.userEmail2,
					method:'get',
					success:(res)=>{
								console.log(this.res)
					}
				})
			}
		}
	}
</script>

<style>
 
</style>
